﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace VisionApplication
{
    class GrayScale : VisionAlgorithm
    {
        public GrayScale(String name, string[] required)
            : base(name, required) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage, Object obj)
        {
          Bitmap returnImage = new Bitmap(sourceImage);
            Graphics g = Graphics.FromImage(returnImage);
            ColorMatrix colorMatrix = new ColorMatrix(
                new float[][] 
                {
                     new float[] {.3f, .3f, .3f, 0, 0},
                     new float[] {.59f, .59f, .59f, 0, 0},
                     new float[] {.11f, .11f, .11f, 0, 0},
                     new float[] {0, 0, 0, 1, 0},
                     new float[] {0, 0, 0, 0, 1}
                });
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
           
            g.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
      0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            this.Image = returnImage;
            return returnImage;
        }
    }
}

